<template>
  <view class="promo-container">
    <!-- 活动头部 -->
    <view class="promo-header">
      <image 
        src="https://images.unsplash.com/photo-1503376780353-7e6692767b70?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=800&q=80" 
        mode="aspectFill" 
        class="header-image"
      ></image>
      <view class="header-overlay"></view>
      <view class="header-content">
        <text class="header-title">限时优惠</text>
        <text class="header-subtitle">超值活动 限时抢购</text>
      </view>
    </view>
    
    <!-- 活动倒计时 -->
    <view class="countdown-section">
      <view class="countdown-title">距离活动结束还剩</view>
      <view class="countdown-timer">
        <u-count-down 
          :time="remainTime" 
          format="DD天 HH时 mm分 ss秒"
          @end="onCountdownEnd"
        ></u-count-down>
      </view>
    </view>
    
    <!-- 活动列表 -->
    <view class="promo-list">
      <view class="promo-item" v-for="(promo, index) in promoList" :key="index">
        <image :src="promo.image" mode="aspectFill" class="promo-image"></image>
        <view class="promo-content">
          <text class="promo-title">{{ promo.title }}</text>
          <text class="promo-desc">{{ promo.desc }}</text>
          <view class="promo-footer">
            <text class="promo-price">¥{{ promo.price }}</text>
            <u-button type="error" size="mini" @click="goToPromo(promo)">立即抢购</u-button>
          </view>
        </view>
      </view>
    </view>
    
    <!-- 活动规则 -->
    <view class="promo-rules">
      <view class="section-title">活动规则</view>
      <view class="rules-content">
        <view class="rule-item">
          <text class="rule-number">1</text>
          <text class="rule-text">活动时间：2023年6月1日 - 2023年6月30日</text>
        </view>
        <view class="rule-item">
          <text class="rule-number">2</text>
          <text class="rule-text">每个用户ID限购买一次</text>
        </view>
        <view class="rule-item">
          <text class="rule-number">3</text>
          <text class="rule-text">优惠券不可与其他优惠叠加使用</text>
        </view>
        <view class="rule-item">
          <text class="rule-number">4</text>
          <text class="rule-text">如有任何疑问，请联系客服</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'

// 剩余时间（毫秒）
const remainTime = ref(24 * 60 * 60 * 1000) // 24小时

// 活动列表
const promoList = ref([
  {
    image: 'https://images.unsplash.com/photo-1494976388531-d1058494cdd8?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=800&q=80',
    title: '夏日清凉套餐',
    desc: '标准洗车+内饰吸尘+玻璃清洁',
    price: 29.9
  },
  {
    image: 'https://images.unsplash.com/photo-1542362567-b07e54358753?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=800&q=80',
    title: '新客专享套餐',
    desc: '标准洗车服务，新用户专享',
    price: 9.9
  },
  {
    image: 'https://images.unsplash.com/photo-1503376780353-7e6692767b70?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=800&q=80',
    title: '会员尊享套餐',
    desc: '至尊洗车+打蜡+内饰深度清洁',
    price: 59.9
  }
])

// 倒计时结束
const onCountdownEnd = () => {
  uni.showToast({ title: '活动已结束', icon: 'none' })
}

// 跳转到活动详情
const goToPromo = (promo: any) => {
  uni.showToast({ title: `抢购${promo.title}`, icon: 'none' })
}
</script>

<style lang="scss" scoped>
.promo-container {
  background-color: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 20rpx;
}

.promo-header {
  position: relative;
  height: 300rpx;
  margin-bottom: 20rpx;
  
  .header-image {
    width: 100%;
    height: 100%;
  }
  
  .header-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, rgba(0,0,0,0.3), rgba(0,0,0,0.7));
  }
  
  .header-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 100%;
    z-index: 2;
    
    .header-title {
      display: block;
      font-size: 48rpx;
      font-weight: bold;
      color: #fff;
      margin-bottom: 20rpx;
    }
    
    .header-subtitle {
      font-size: 28rpx;
      color: rgba(255,255,255,0.9);
    }
  }
}

.countdown-section {
  background-color: #fff;
  padding: 40rpx 20rpx;
  margin-bottom: 20rpx;
  text-align: center;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05);
  
  .countdown-title {
    font-size: 32rpx;
    color: #333;
    margin-bottom: 20rpx;
  }
  
  .countdown-timer {
    ::v-deep .u-count-down {
      .u-count-down__text {
        font-size: 36rpx;
        font-weight: bold;
        color: #ff6600;
      }
    }
  }
}

.promo-list {
  padding: 0 20rpx 20rpx;
  
  .promo-item {
    background-color: #fff;
    border-radius: 20rpx;
    overflow: hidden;
    margin-bottom: 20rpx;
    box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05);
    
    .promo-image {
      width: 100%;
      height: 200rpx;
    }
    
    .promo-content {
      padding: 20rpx;
      
      .promo-title {
        display: block;
        font-size: 32rpx;
        font-weight: bold;
        color: #333;
        margin-bottom: 10rpx;
      }
      
      .promo-desc {
        display: block;
        font-size: 26rpx;
        color: #666;
        margin-bottom: 20rpx;
      }
      
      .promo-footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
        
        .promo-price {
          font-size: 36rpx;
          font-weight: bold;
          color: #ff6600;
        }
      }
    }
  }
}

.section-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  padding: 30rpx 20rpx 20rpx;
  border-bottom: 1rpx solid #f0f0f0;
  background-color: #fff;
}

.promo-rules {
  background-color: #fff;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05);
  
  .rules-content {
    padding: 20rpx;
    
    .rule-item {
      display: flex;
      align-items: flex-start;
      margin-bottom: 20rpx;
      
      .rule-number {
        width: 40rpx;
        height: 40rpx;
        background-color: #007aff;
        color: #fff;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24rpx;
        margin-right: 20rpx;
        flex-shrink: 0;
      }
      
      .rule-text {
        font-size: 26rpx;
        color: #666;
        line-height: 1.5;
      }
    }
  }
}
</style>